package com.fosu.web.controller;


import com.alibaba.fastjson.JSONObject;
import com.fosu.common.ResponseResult;
import com.fosu.domain.User;
import com.fosu.service.UserService;
import com.fosu.service.WeChatService;
import com.fosu.service.impl.GetToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Desription
 * 用户类接口
 *
 * @author manno
 * @date 2020/10/10
 */
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private WeChatService weChatService;
    @Autowired
    private GetToken getToken;

    @GetMapping("/getAllUser")
    public ResponseResult getAllUser(HttpServletResponse resp) {
        return userService.findAll(resp);
    }

    @GetMapping("/getUserById")
    public ResponseResult getUserById(@RequestParam("userId") int userId, HttpServletResponse resp) {
        return userService.findUserById(resp, userId);
    }


    @PostMapping("/login")
    public ResponseResult login(HttpServletResponse resp, @RequestBody JSONObject jsonPram) throws Exception {
        return weChatService.wxLogin(resp, jsonPram);
    }

    @PostMapping("/editUserNickName")
    public ResponseResult editUserNickName(HttpServletResponse resp, @RequestBody JSONObject newNickName) {
        System.out.println(newNickName.toJSONString());
        return userService.editUserNickName(resp, newNickName);
    }

    @PostMapping("/editUserCampus")
    public ResponseResult editUserCampus(HttpServletResponse resp, @RequestBody JSONObject newCampus) {
        return userService.editUserCampus(resp, newCampus);
    }

    @PostMapping("/editUserPhone")
    public ResponseResult editUserPhone(HttpServletResponse resp, @RequestBody JSONObject newPhone) {
        return userService.editUserPhone(resp, newPhone);
    }

    @PostMapping("/editUserWechat")
    public ResponseResult editUserWechat(HttpServletResponse resp, @RequestBody JSONObject newWechat) {
        return userService.editUserWechat(resp, newWechat);
    }

    @GetMapping("/iReleased")
    public ResponseResult userReleased(HttpServletResponse resp, @RequestParam("userId") Integer userId) {
        return userService.iReleased(resp, userId);
    }

    public ResponseResult getToken(HttpServletResponse resp, @RequestParam("code") String code) {
        return getToken.getToken(resp, code);
    }

    @GetMapping("/getReplyMe")
    public ResponseResult getReplyMe(HttpServletResponse resp, Integer userId)
    {
        return  userService.getReplyMe(resp, userId);
    }

}
